package com.jeesite.modules.kj.api.controller;


import com.jeesite.common.collect.ListUtils;
import com.jeesite.modules.kj.api.vo.response.BadgeResponseVo;
import com.jeesite.modules.kj.api.vo.response.BannerResponseVo;
import com.jeesite.modules.kj.api.vo.response.SummaryResponseVo;
import com.jeesite.modules.kj.api.vo.responseVo.ResponseBean;
import com.jeesite.modules.kj.entity.KjBadge;
import com.jeesite.modules.kj.entity.KjBanner;
import com.jeesite.modules.kj.entity.KjMember;
import com.jeesite.modules.kj.service.KjBannerService;
import com.jeesite.modules.kj.service.KjMemberIntegralsService;
import com.jeesite.modules.kj.service.KjMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.Banner;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.math.BigDecimal;
import java.util.List;

/**
 * Author:hzy
 * Date:2021/07/04
 * Description:
 */
@Api(value = "首页api", tags = {"首页api"})
@Slf4j
@Controller
@RequestMapping(value = "/api/index")
public class IndexApiController {
    @Autowired
    KjBannerService kjBannerService;
    @Autowired
    KjMemberService kjMemberService;
    @Autowired
    KjMemberIntegralsService kjMemberIntegralsService;

    @ApiOperation(value = "获取banner图", notes = "获取banner图")
    @GetMapping(value = "getBanner")
    public ResponseBean<List<BannerResponseVo>> getBanner() {
        List<KjBanner> banners = kjBannerService.findList(new KjBanner());
        List<BannerResponseVo> results = ListUtils.newArrayList();
        for (KjBanner banner: banners
             ) {
            results.add(new BannerResponseVo(banner));
        }
        return new ResponseBean<>(results);
    }



    @ApiOperation(value = "系统统计", notes = "系统统计")
    @GetMapping(value = "summary")
    public ResponseBean<SummaryResponseVo> summary() {
        SummaryResponseVo results = new SummaryResponseVo();
        long totalUsers = kjMemberService.findCount(new KjMember());
        BigDecimal totalIntegrals = kjMemberIntegralsService.getTotalIntegrals();
        BigDecimal totalHours = kjMemberIntegralsService.getTotalHours();
        results.setTotalUser(totalUsers);
        results.setTotalIntegrals(totalIntegrals);
        results.setTotalHours(totalHours.add(BigDecimal.valueOf(9101)));
        return new ResponseBean<>(results);
    }


}
